<?php
/**********************************************************************************
WIKINDX: Bibliographic Management system.
Copyright (C)

This program is free software; you can redistribute it and/or modify it under the terms 
of the GNU General Public License as published by the Free Software Foundation; either 
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; 
if not, write to the 
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

The WIKINDX Team 2007
sirfragalot@users.sourceforge.net
**********************************************************************************/
/*****
*	RESOURCEFORM class.
*
*	FORM creation for new/edit resources
*
*	$Header: /cvsroot/wikindx/wikindx3/core/resource/RESOURCEFORM.php,v 1.83 2008/01/01 10:04:14 sirfragalot Exp $
*****/
class RESOURCEFORM
{
// Constructor
	function RESOURCEFORM($db, $vars)
	{
		$this->db = $db;
		$this->vars = $vars;
		include_once("core/session/SESSION.php");
		$this->session = new SESSION();
		include_once("core/messages/MESSAGES.php");
		$this->messages = new MESSAGES();
		include_once("core/html/MISC.php");
		include_once("core/html/HTML.php");
		$this->html = new HTML();
		include_once("core/html/FORM.php");
		include_once("core/html/TABLE.php");
		include_once("core/resource/RESOURCEMAP.php");
		$this->map = new RESOURCEMAP();
	}
/*
* Make a form text field ready for printing.
*
* @author Mark Grimshaw
* @version 1
* @param array/string field
* @param array session variables
* @param integer text input size (optional)
* @param integer text input maxSize (optional)
* @return string
*/
	function makeTextInput($field, $sessionVars, $size = FALSE, $maxSize = FALSE)
	{
		if(is_array($field))
			list($field, $message) = array_values($field);
		else
			$message = $field;
		if(array_key_exists($field, $sessionVars))
			return FORM::textInput($this->messages->text("resources", $message), "resource_$field", 
				$this->html->dbToFormTidy($sessionVars[$field]), $size, $maxSize);
		else
			return FORM::textInput($this->messages->text("resources", $message), "resource_$field", 
				FALSE, $size, $maxSize);
	}
// start creating a new resource
	function stage1($new = TRUE)
	{
		include_once("core/messages/UTF8.php");
		$this->utf8 = new UTF8();
		foreach($this->map->types as $key)
			$array[$key] = $this->utf8->encodeUtf8($this->messages->text("resourceType", $key));
		$pString = '';
		$sessionVars = $this->session->getArray('resource');
		if(!$sessionVars)
			$sessionVars = array();
// editing
		if(!$new)
			$pString .= FORM::hidden("resource_type", $sessionVars['type']);
		$pString .= FORM::hidden("method", 'stage2');
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		if($new)
		{
			if(array_key_exists('type', $sessionVars))
				$pString .= TABLE::td(FORM::selectedBoxValue(
				$this->messages->text("resources", "type"), 
				"resource_type", $array, $sessionVars['type'], 10) . " " . 
				MISC::span('*', 'required'));
			else
				$pString .= TABLE::td(FORM::selectFBoxValue($this->messages->text("resources", "type"), 
				"resource_type", $array, 10) . " " . MISC::span('*', 'required'));
		}
		else
		{
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
// Encapsulating cell from body.tpl
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
		}
		$title = array_key_exists("title", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars['title']) : FALSE;
		$title = array_key_exists("noSort", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars['noSort']) . " $title" : FALSE . $title;
		$subtitle = array_key_exists("subtitle", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars['subtitle']) : FALSE;
		$shortTitle = array_key_exists("shortTitle", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars['shortTitle']) : FALSE;
		$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "title"), 
			"resource_title", $title, 50) . " " . MISC::span('*', 'required') . MISC::br() . 
			FORM::textInput($this->messages->text("resources", "subtitle"), "resource_subtitle", 
			$subtitle, 50) . MISC::br() . 
			FORM::textInput($this->messages->text("resources", "shortTitle"), 
			"resource_shortTitle", $shortTitle, 50). MISC::br() . $this->messages->text("hint", "capitals"));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		if($new)
		{
// Are there collections?
			$resultset = $this->db->select(array('WKX_collection'), 'id');
			if($this->db->numRows($resultset))
				$pString .= TABLE::td(MISC::br() . MISC::br() . 
					$this->messages->text("collection", "addToCollection") . "&nbsp;&nbsp;" . 
					FORM::checkBox(FALSE, "resource_addToCollection"));
			else
				$pString .= TABLE::td("&nbsp;");
			$pString .= TABLE::td(FORM::formSubmit("Proceed"), FALSE, "right", "bottom");
		}
		else
		{
			$td = MISC::p(MISC::br() . FORM::selectedBoxValue(
				$this->messages->text("resources", "convertType"), 
				"resource_typeConvert", $array, $sessionVars['type'], 10) . " " . 
				MISC::span('*', 'required'));
			include_once("core/collection/COLLECTIONMAP.php");
			$map = new COLLECTIONMAP();
			if(array_key_exists($sessionVars['type'], $map->collectionTypes))
				$td .= MISC::p($this->messages->text("collection", "changeCollection") . "&nbsp;&nbsp;" . 
						FORM::checkBox(FALSE, "resource_changeCollection") . MISC::br() . 
						$this->messages->text('hint', 'changeCollection'));
			$pString .= TABLE::td($td) . TABLE::td(FORM::formSubmit("Proceed"), FALSE, "right", "bottom");
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Stage 1a -display existing collections for this resource type so user can add this new resource to a collection.
// If $noId != FALSE, this is the collection ID stored with this resource and which should not appear in the list as the user now wishes to change the collection of which this resource is a part.
	function stage1a($collections, $sessionVars = FALSE, $edit = FALSE, $noId = FALSE)
	{
		$pString = FORM::hidden("method", 'stage1a');
		if($edit)
		{
			$this->session->delVar("resource_collection");
			$sessionVars = $this->addNamesToSession($sessionVars);
			$pString .= FORM::hidden('resource_type', $this->vars['resource_type']);
			if(!$noId)
				$pString .= FORM::hidden('resource_typeConvert', $this->vars['resource_typeConvert']);
// remove existing collection
			else
				unset($collections[$noId]);
		}
		$pString .= MISC::p($this->messages->text("collection", "addToChooseCollection"));
// Add ignore to collections list
		$temp[0] = $this->messages->text("misc", "ignore");
		foreach($collections as $key => $value)
			$temp[$key] = $value;
		$collections = $temp;
		$pString .= FORM::selectFBoxValue(FALSE, "resource_collectionId", $collections, 20, 80);
		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= MISC::p(FORM::formSubmit("Proceed"), FALSE, "right");
		return $pString;
	}
// Stage 2 - select number of creators for this resource.
// Dependent on resource type
	function stage2($sessionVars, $new = TRUE)
	{
		$pString = '';
		if(!$new)
		{
			$sessionVars = $this->addNamesToSession($sessionVars);
			if(array_key_exists('resource_collectionId', $this->vars))
				$pString .= FORM::hidden('resource_collectionId', $this->vars['resource_collectionId']);
		}
		$pString .= FORM::hidden("method", 'stage3');
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$message = $new ? $this->messages->text("resources", "numContributors") : 
			$this->messages->text("resources", "numContributorsEdit");
		$pString .= TABLE::td(MISC::p($message), "", "left", "top");
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd() . MISC::br() . "&nbsp;" . MISC::br();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= $this->creatorInput($new, $sessionVars);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::trStart();
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd() . MISC::br() . "&nbsp;" . MISC::br();
// Encapsulating cell from body.tpl
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= TABLE::td(MISC::br() . "&nbsp;" . MISC::hr() . "&nbsp;" . MISC::br() . 
			MISC::p(FORM::formSubmit("Proceed"), FALSE, "right"), FALSE, "left", "top");
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// set numcreators, names etc. in session.  Needs to be here in stage2 in case user hits back button when editing to get
// back to this stage.  With this function in RESOURCEEDIT at start of process, num_creatorx was not being picked 
// up.
	function addNamesToSession($sessionVars)
	{
		$row = unserialize($this->session->getVar("resourceEditRow"));
		$creatorTypes = array("creator1", "creator2", "creator3", "creator4", "creator5");
		$names = array("surname", "firstname", "initials", "prefix");
		foreach($creatorTypes as $creatorType)
		{
			if($row[$creatorType])
				$temp['num_' . $creatorType] = sizeof(explode(',', $row[$creatorType]));
		}
		$sqlArray = $names;
		$sqlArray[] = 'id';
		foreach($creatorTypes as $creatorType)
		{
			if($row[$creatorType])
			{
				$condition = array();
				$ids = explode(',', $row[$creatorType]);
				foreach($ids as $id)
					$condition[] = $this->db->formatField('id') . "=" . 
					$this->db->tidyInput($id);
				$recordset = $this->db->select(array('WKX_creator'), $sqlArray, 
					" WHERE " . implode(" OR ", $condition));
				while($line = $this->db->loopRecordSet($recordset))
				{
					foreach($names as $name)
					{
						if($name == 'initials')
							$line[$name] = $line[$name] ? str_replace(" ", ".", $line[$name]) . "." : FALSE;
						$collectNames[$line['id']][$name] = $line[$name];
					}
				}
				$index = 1;
				foreach($ids as $id)
				{
					foreach($names as $name)
					{
						if(!$collectNames[$id][$name])
							continue;
						$temp[$creatorType . "_" . $index . "_" . $name] =
							$collectNames[$id][$name];
					}
					$index ++;
				}
			}
		}
		if(isset($temp))
		{
			foreach($temp as $key => $value)
			{
				$sessionVars[$key] = $value;
				$this->session->setVar("resource_" . $key, $value);
			}
		}
		return $sessionVars;
	}
// Create creator input for stage2
// 5 creator fields
	function creatorInput($new, $sessionVars)
	{
		$pString = '';
		$type = $sessionVars['type'];
// Remove creator fields when editing for those creators that are part of a collection
		if($this->session->getVar("resource_collectionId"))
		{
			include_once("core/collection/COLLECTIONMAP.php");
			$this->collectionMap = new COLLECTIONMAP();
			if(array_key_exists($type, $this->collectionMap->collectionTypes))
			{
				foreach($this->collectionMap->{$this->collectionMap->collectionTypes[$type]}['resource_creator'] 
					as $creatorField => $null)
					unset($this->map->{$type}['resource_creator'][$creatorField]);
			}
		}
		foreach($this->map->{$type}['resource_creator'] as $key => $label)
		{
			$typeLabel = 'num_' . $key;
			$pString .= TABLE::td($this->createOneCreator($new, $sessionVars, $label, $typeLabel));
		}
		return $pString;
	}
// Create a creator field
	function createOneCreator($new, $sessionVars, $label, $typeLabel)
	{
		$inputName = "resource_" . $typeLabel;
		if(array_key_exists($typeLabel, $sessionVars) && is_numeric($sessionVars[$typeLabel]))
		{
			$rangeStart = $new ? 0 : $sessionVars[$typeLabel];
			$rangeEnd = $sessionVars[$typeLabel] + 5;
			$td = FORM::selectedBox($this->messages->text("creators", $label), 
				$inputName, range($rangeStart, $rangeEnd), $sessionVars[$typeLabel], "6");
		}
		else
			$td = FORM::textInput($this->messages->text("creators", $label), $inputName, FALSE, 4, 3);
		return $td;
	}
// new resource: Stage 3 (enter contributor names)
	function stage3($sessionVars, $new = TRUE)
	{
		if(array_key_exists("resource_typeConvert", $this->vars))
			$sessionVars = $this->addNamesToSession($sessionVars);
// Display type and title etc.
		$pString = MISC::b($sessionVars['type']) . ':&nbsp;&nbsp;' . $sessionVars['title'];
		if(array_key_exists('subtitle', $sessionVars) && $sessionVars['subtitle'])
			$pString .= ':&nbsp;&nbsp;' . $sessionVars['subtitle'];
		if(array_key_exists('shortTitle', $sessionVars) && $sessionVars['shortTitle'])
			$pString .= '&nbsp;&nbsp;(' . $sessionVars['shortTitle'] . ')';
		$pString = stripslashes(MISC::p(MISC::i($pString), FALSE, 'center'));
		include_once("core/creator/CREATOR.php");
		$creator = new CREATOR($this->db);
		$creators = $creator->grabAll();
		$type = $sessionVars['type'];
// Remove creator fields when editing for those creators that are part of a collection
		if($this->session->getVar("resource_collectionId"))
		{
			include_once("core/collection/COLLECTIONMAP.php");
			$this->collectionMap = new COLLECTIONMAP();
			if(array_key_exists($type, $this->collectionMap->collectionTypes))
			{
				foreach($this->collectionMap->{$this->collectionMap->collectionTypes[$type]}['resource_creator'] 
					as $creatorField => $null)
					unset($this->map->{$type}['resource_creator'][$creatorField]);
			}
		}
		if($creators)
		{
			$temp[0] = $this->messages->text("misc", "ignore");
			foreach($creators as $key => $value)
				$temp[$key] = $value;
			$creators = $temp;
		}
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$found = FALSE;
		foreach($this->map->{$type}['resource_creator'] as $typeLabel => $label)
		{
			$sessionType = "resource_num_" . $typeLabel;
			if($num = $this->session->getVar($sessionType))
			{
				$pString .= TABLE::trStart();
				$pString .= TABLE::td(MISC::b($this->messages->text("creators", $label)), 
					"", "", "", 5);
				$pString .= TABLE::trEnd();
// Print labels only first time around
				if(!$found)
				{
					$pString .= TABLE::trStart();
					$pString .= TABLE::td($this->messages->text("resources", "firstname"));
					$pString .= TABLE::td($this->messages->text("resources", "initials") . 
						MISC::br() . $this->messages->text("hint", "initials"));
					$pString .= TABLE::td($this->messages->text("resources", "prefix"));
					$pString .= TABLE::td($this->messages->text("resources", "surname"));
					$pString .= TABLE::td($this->messages->text("hint", "resourceName"));
					$pString .= TABLE::trEnd();
				}
				$pString .= $this->nameForm($creators, $sessionVars, $num, $typeLabel, $found);
				$found = TRUE;
				$this->session->delVar($sessionType);
			}
		}
		$finish = FALSE;
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		if($found)
			$pString .= MISC::hr();
//		$pString .= MISC::br();
		$pString .= $this->stage4($sessionVars, $new);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= $this->stage5($sessionVars, $new);
		$pString .= MISC::p($finish . FORM::formSubmit("Proceed"), FALSE, "right");
		return $pString;
	}
// new resource: Stage 4 (Fields specific to resource types)
	function stage4($sessionVars, $new = TRUE)
	{
		if(array_key_exists("jump", $this->vars) || $this->session->getVar('resource_typeConvert'))
			$sessionVars = $this->addNamesToSession($sessionVars);
//		$pString = FORM::hidden("method", 'stage5');
		$pString = '';
// book type
		if($sessionVars['type'] == 'book')
			$pString .= $this->bookForm($sessionVars);
// book_article type
		else if($sessionVars['type'] == 'book_article')
			$pString .= $this->bookArticleForm($sessionVars);
// book_chapter type
		else if($sessionVars['type'] == 'book_chapter')
			$pString .= $this->bookArticleForm($sessionVars);
// journal_article type
		else if($sessionVars['type'] == 'journal_article')
			$pString .= $this->journalArticleForm($sessionVars);
// web_site type
		else if($sessionVars['type'] == 'web_site')
			$pString .= $this->webSiteForm($sessionVars);
// web_article type
		else if($sessionVars['type'] == 'web_article')
			$pString .= $this->webArticleForm($sessionVars);
// web_encyclopedia type
		else if($sessionVars['type'] == 'web_encyclopedia')
			$pString .= $this->webEncyclopediaForm($sessionVars);
// web_encyclopedia_article type
		else if($sessionVars['type'] == 'web_encyclopedia_article')
			$pString .= $this->webEncyclopediaArticleForm($sessionVars);
// newspaper_article type
		else if($sessionVars['type'] == 'newspaper_article')
			$pString .= $this->newspaperArticleForm($sessionVars);
// magazine_article type
		else if($sessionVars['type'] == 'magazine_article')
			$pString .= $this->magazineArticleForm($sessionVars);
// proceedings type
		else if($sessionVars['type'] == 'proceedings')
			$pString .= $this->proceedingsForm($sessionVars);
// conference_paper type
		else if($sessionVars['type'] == 'conference_paper')
			$pString .= $this->conferencePaperForm($sessionVars);
// proceedings_article type
		else if($sessionVars['type'] == 'proceedings_article')
			$pString .= $this->proceedingsArticleForm($sessionVars);
// thesis type
		else if($sessionVars['type'] == 'thesis')
			$pString .= $this->thesisForm($sessionVars);
// film type
		else if($sessionVars['type'] == 'film')
			$pString .= $this->filmForm($sessionVars);
// broadcast type
		else if($sessionVars['type'] == 'broadcast')
			$pString .= $this->broadcastForm($sessionVars);
// software type
		else if($sessionVars['type'] == 'software')
			$pString .= $this->softwareForm($sessionVars);
// artwork type
		else if($sessionVars['type'] == 'artwork')
			$pString .= $this->artworkForm($sessionVars);
// audiovisual type
		else if($sessionVars['type'] == 'audiovisual')
			$pString .= $this->audiovisualForm($sessionVars);
// (legal) case type
		else if($sessionVars['type'] == 'case')
			$pString .= $this->caseForm($sessionVars);
// legal_ruling / regulation type
		else if($sessionVars['type'] == 'legal_ruling')
			$pString .= $this->legalRuleForm($sessionVars);
// (parliamentary) bill type
		else if($sessionVars['type'] == 'bill')
			$pString .= $this->billForm($sessionVars);
// classical work type
		else if($sessionVars['type'] == 'classical')
			$pString .= $this->classicalForm($sessionVars);
// government report (and documentation)type
		else if($sessionVars['type'] == 'government_report')
			$pString .= $this->governmentReportForm($sessionVars);
// report (and documentation)type
		else if($sessionVars['type'] == 'report')
			$pString .= $this->reportForm($sessionVars);
// government/legal hearing type
		else if($sessionVars['type'] == 'hearing')
			$pString .= $this->hearingForm($sessionVars);
// online database type
		else if($sessionVars['type'] == 'database')
			$pString .= $this->databaseForm($sessionVars);
// online manuscript type
		else if($sessionVars['type'] == 'manuscript')
			$pString .= $this->manuscriptForm($sessionVars);
// map type
		else if($sessionVars['type'] == 'map')
			$pString .= $this->mapForm($sessionVars);
// chart type
		else if($sessionVars['type'] == 'chart')
			$pString .= $this->chartForm($sessionVars);
// statute type
		else if($sessionVars['type'] == 'statute')
			$pString .= $this->statuteForm($sessionVars);
// patent type
		else if($sessionVars['type'] == 'patent')
			$pString .= $this->patentForm($sessionVars);
// personal type
		else if($sessionVars['type'] == 'personal')
			$pString .= $this->personalForm($sessionVars);
// music_album type
		else if($sessionVars['type'] == 'music_album')
			$pString .= $this->musicAlbumForm($sessionVars);
// music_track type
		else if($sessionVars['type'] == 'music_track')
			$pString .= $this->musicTrackForm($sessionVars);
// music_score type
		else if($sessionVars['type'] == 'music_score')
			$pString .= $this->musicScoreForm($sessionVars);
// unpublished type
		else if($sessionVars['type'] == 'unpublished')
			$pString .= $this->unpublishedForm($sessionVars);
// miscellaneous type
		else if($sessionVars['type'] == 'miscellaneous')
			$pString .= $this->miscellaneousForm($sessionVars);
// miscellaneous section type
		else if($sessionVars['type'] == 'miscellaneous_section')
			$pString .= $this->miscellaneousSectionForm($sessionVars);
		if(!$new)
			$finish = $this->messages->text("resources", "finish") . "&nbsp;&nbsp;" . 
			FORM::checkbox(FALSE, "resource_finish") . "&nbsp;&nbsp;";
		else
			$finish = FALSE;
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::hr();
//		$pString .= MISC::p($finish . FORM::formSubmit("Proceed"), FALSE, "right");
		return $pString;
	}
// new resource: Stage 5 - Final stage
	function stage5($sessionVars, $new = TRUE)
	{
		if(array_key_exists("jump", $this->vars))
			$sessionVars = $this->addNamesToSession($sessionVars);
		$pString = $this->abstractForm($sessionVars);
		if(($sessionVars['type'] == 'web_site') || ($sessionVars['type'] == 'web_article') || 
			($sessionVars['type'] == 'database') || ($sessionVars['type'] == 'web_encyclopedia') ||
			($sessionVars['type'] == 'web_encyclopedia_article'))
			$pString .= $this->urlIsbnForm($sessionVars, TRUE);
		else
			$pString .= $this->urlIsbnForm($sessionVars, FALSE);
		$pString .= $this->groupKeywordForm($sessionVars, $new);
//		$pString .= $this->noteForm($sessionVars);
		$pString .= $this->customFields($sessionVars, $new);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::p(FORM::formSubmit("Proceed"), FALSE, "right");
		return $pString;
	}
// Display stage4 for book type
	function bookForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year2', 31, 30);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("numPages", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 6, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "integer",
			$this->messages->text("resources", "numberOfVolumes") . " ");
		$field = array_search("numberOfVolumes", $this->map->{$type}['resource_misc']);
		$pString .= $this->textElement($sessionVars, 'resource_misc', $field, 5, 4, $extra);
		$field = array_search("bookVolumeNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$extra = MISC::br() . $this->messages->text("hint", "volumeYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year3', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("seriesTitle", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$field = array_search("seriesNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
//		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
//		$pString .= TABLE::trStart();
		$pString .= $this->translationForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		return $pString;
	}
// Display stage4 for book_article type
	function bookArticleForm($sessionVars)
	{
		$type = $sessionVars['type'];
//		$pString = MISC::hr();
		$pString = '';
// If converting to a book_chapter, chapter title must be an integer
		if($this->session->getVar('resource_typeConvert') && ($type == 'book_chapter'))
		{
			$title = array_key_exists("title", $sessionVars) ? 
				$this->html->dbToFormTidy($sessionVars['title']) : FALSE;
			$title = array_key_exists("noSort", $sessionVars) ? 
				$this->html->dbToFormTidy($sessionVars['noSort']) . " $title" : FALSE . $title;
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "chapter"), 
				"resource_title", $title, 10) .  " " . MISC::span('*', 'required') . 
				MISC::br() . $this->messages->text("hint", "integer", 
				$this->messages->text("resources", "chapter") . " "));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
		}
// Editing so don't show collection details
		if($this->session->getVar("resource_collectionId"))
		{
// print existing Collection
			if($title = $this->session->getVar("resource_collection"))
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$field = array_search("bookVolumeNumber", $this->map->{$type}['resource']);
			$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
		}
		else
		{
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
			$pString .= $this->publisherForm($sessionVars);
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
			$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
			$pString .= $this->textElement($sessionVars, 'resource_year', 'year2', 31, 30);
			$field = array_search("edition", $this->map->{$type}['resource']);
			$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$extra = MISC::br() . $this->messages->text("hint", "integer",
				$this->messages->text("resources", "numberOfVolumes") . " ");
			$field = array_search("numberOfVolumes", $this->map->{$type}['resource_misc']);
			$pString .= $this->textElement($sessionVars, 'resource_misc', $field, 5, 4, $extra);
			$field = array_search("bookVolumeNumber", $this->map->{$type}['resource']);
			$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
			$extra = MISC::br() . $this->messages->text("hint", "volumeYear");
			$pString .= $this->textElement($sessionVars, 'resource_year', 'year3', 31, 30, $extra);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$field = array_search("seriesTitle", $this->map->{$type}['resource']);
			$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
			$field = array_search("seriesNumber", $this->map->{$type}['resource']);
			$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
		}
		$pString .= $this->pagesForm($sessionVars);
//		$pString .= MISC::br();
		if(!$this->session->getVar("resource_collectionId"))
		{
//			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
//			$pString .= TABLE::trStart();
			$pString .= $this->translationForm($sessionVars);
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
		}
		return $pString;
	}
// Display stage4 for journal_article type
	function journalArticleForm($sessionVars)
	{
		include_once("core/messages/CONSTANTS.php");
		$constant = new CONSTANTS();
		$type = $sessionVars['type'];
//		$pString = MISC::hr() . MISC::br();
		$pString = '';
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
// print existing Collection
		else
		{
			if($title = $this->session->getVar("resource_collection"))
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
		}
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= $this->dateForm($sessionVars, TRUE);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("journalVolumeNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("journalIssueNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for newspaper_article type
	function newspaperArticleForm($sessionVars)
	{
		$type = $sessionVars['type'];
//		$pString = MISC::hr() . MISC::br();
		$pString = '';
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
// print existing Collection
		else
		{
			if($title = $this->session->getVar("resource_collection"))
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
		}
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$field = array_search("section", $this->map->{$type}['resource']);
		$pString .= TABLE::td($this->makeTextInput(array($field, 
			$this->map->{$type}['resource'][$field]), $sessionVars, 20, 255));
		if(!$this->session->getVar("resource_collectionId"))
		{
			$field = array_search("city", $this->map->{$type}['resource']);
			$pString .= TABLE::td($this->makeTextInput(array($field, 
				$this->map->{$type}['resource'][$field]), $sessionVars, 20, 255));
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for magazine_article type
	function magazineArticleForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = '';
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
// print existing Collection
		else
		{
			if($title = $this->session->getVar("resource_collection"))
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
		}
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= $this->dateForm($sessionVars, TRUE);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= $this->textElement($sessionVars, 'resource', 'field4', 30, 255);
		$field = array_search("issueNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("typeOfArticle", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for web_site type
	function webSiteForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->urlForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for web_article type
	function webArticleForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = '';
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= $this->publisherForm($sessionVars);
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
		}
		$pString .= $this->urlForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::hr();
		if(!$this->session->getVar("resource_collectionId"))
			$pString .= $this->collectionForm($sessionVars);
// print existing Collection
		else
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			if($title = $this->session->getVar("resource_collection"))
				$pString .= TABLE::td(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= TABLE::td(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		
// Load month arrays
		include_once("core/messages/CONSTANTS.php");
		$constant = new CONSTANTS();
		$days[] = $this->messages->text("misc", "ignore");
		$days = array_merge($days, range(1, 31));
		$months[] = $this->messages->text("misc", "ignore");
		$months = array_merge($months, $constant->constants->monthToLongName());
		$dayText = $monthText = 0;// 'IGNORE'
		if(array_key_exists('miscField5', $sessionVars) && $sessionVars['miscField5'])
			$dayText = $sessionVars['miscField5'];
		if(array_key_exists('miscField6', $sessionVars) && $sessionVars['miscField6'])
			$monthText = $sessionVars['miscField6'];
		$pString .= TABLE::td(FORM::selectedBoxValue($this->messages->text("resources", "publicationDay"),
			"resource_miscField5", $days, $dayText, "6"));
		$pString .= TABLE::td(FORM::selectedBoxValue($this->messages->text("resources", "publicationMonth"), 
			"resource_miscField6", $months, $monthText, "6"));
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 21, 20, $extra);
		
		$field = array_search("journalVolumeNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("journalIssueNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource' , $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for web_encyclopedia type
	function webEncyclopediaForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->urlForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$extra = MISC::br() . $this->messages->text("hint", "revisionYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year3', 31, 30, $extra);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for web_encyclopedia_article type
	function webEncyclopediaArticleForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = '';
		$pString .= $this->urlForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::hr();
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= $this->publisherForm($sessionVars);
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= MISC::br();
		}
		if(!$this->session->getVar("resource_collectionId"))
			$pString .= $this->collectionForm($sessionVars);
// print existing Collection
		else
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			if($title = $this->session->getVar("resource_collection"))
				$pString .= TABLE::td(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= TABLE::td(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$extra = MISC::br() . $this->messages->text("hint", "revisionYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year3', 31, 30, $extra);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for proceedings type
	function proceedingsForm($sessionVars)
	{
//		$pString = $this->collectionForm($sessionVars);
//		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= $this->dateForm($sessionVars, TRUE);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for conference_paper type
	function conferencePaperForm($sessionVars)
	{
		$type = $sessionVars['type'];
//		$pString = MISC::hr() . MISC::br();
		$pString = '';
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
// print existing Collection
		else
		{
			if($title = $this->session->getVar("resource_collection"))
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
		}
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= $this->dateForm($sessionVars, TRUE);
		return $pString;
	}
// Display stage4 for proceedings_article type
	function proceedingsArticleForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = '';
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
// print existing Collection
		else
		{
			if($title = $this->session->getVar("resource_collection"))
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
		}
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars, TRUE);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("seriesTitle", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$field = array_search("seriesNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("proceedingsVolumeNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();		
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for thesis type
	function thesisForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= TABLE::td(MISC::b($this->messages->text("resources", "thesis")));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("thesisLabel", $this->map->{$type}['resource']);
		if(array_key_exists($field, $sessionVars))
		{
			$value = $this->html->dbToFormTidy($sessionVars[$field]);
			$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "thesisType"), 
				"resource_$field", $value, 10) . MISC::br() . $this->messages->text("hint", "thesisType"));
		}
		else
			$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "thesisType"), 
				"resource_$field", FALSE, 10) . MISC::br() . $this->messages->text("hint", "thesisType"));
		$field = array_search("thesis", $this->map->{$type}['resource']);
		if(array_key_exists($field, $sessionVars) && $sessionVars[$field])
		{
			$value = $this->html->dbToFormTidy($sessionVars[$field]);
			$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "thesisLabel"), 
				"resource_$field", $value, 10) . MISC::br() . $this->messages->text("hint", "thesisLabel"));
		}
		else
			$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "thesisLabel"), 
				"resource_$field", FALSE, 10) . MISC::br() . $this->messages->text("hint", "thesisLabel"));
		$field = array_search("thesisYear", $this->map->{$type}['resource_year']);
		$pString .= TABLE::td($this->makeTextInput(array($field, 
			$this->map->{$type}['resource_year'][$field]), $sessionVars, 31, 30) . MISC::br() . 
			$this->messages->text("hint", "year"));
		$field = array_search("numPages", $this->map->{$type}['resource']);
		$pString .= TABLE::td($this->textElement($sessionVars, 'resource', $field, 6, 255));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::hr();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "thesisAbstract")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
// print existing Collection
		else
		{
			if($title = $this->session->getVar("resource_collection"))
				$pString .= TABLE::td(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString .= TABLE::td(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
		}
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year2', 31, 30, $extra);
		$field = array_search("journalVolumeNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("journalIssueNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for film type
	function filmForm($sessionVars)
	{
		$pString = $this->publisherFormB($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->filmTVForm($sessionVars);
		return $pString;
	}
// Display stage4 for broadcast type
	function broadcastForm($sessionVars)
	{
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->filmTVForm($sessionVars);
		return $pString;
	}
// Display stage4 for artwork type
	function artworkForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("medium", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for software type
	function softwareForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("version", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("typeOfSoftware", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for audiovisual type
	function audiovisualForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("medium", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "integer",
			$this->messages->text("resources", "numberOfVolumes") . " ");
		$field = array_search("numberOfVolumes", $this->map->{$type}['resource_misc']);
		$pString .= $this->textElement($sessionVars, 'resource_misc', $field, 5, 4, $extra);
		$field = array_search("bookVolumeNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$extra = MISC::br() . $this->messages->text("hint", "volumeYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year3', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("seriesTitle", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$field = array_search("seriesNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for legal_rule type
	function legalruleForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("section", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("ruleNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("ruleType", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for case type
	function caseForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherFormB($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("reporter", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("reporterVolume", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for bill type
	function billForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("code", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("codeVolume", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$extra =  MISC::br() . $this->messages->text("hint", "year");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("session", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("section", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("billNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for classical type
	function classicalForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("volume", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for government_report type
	function governmentReportForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("department", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$field = array_search("section", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("volume", $this->map->{$type}['resource']);
		$field = array_search("issueNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for report type
	function reportForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("seriesTitle", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("issueNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("typeOfReport", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for hearing type
	function hearingForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("legislativeBody", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("committee", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("session", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "integer",
			$this->messages->text("resources", "numberOfVolumes") . ' ');
		$field = array_search("numberOfVolumes", $this->map->{$type}['resource_misc']);
		$pString .= $this->textElement($sessionVars, 'resource_misc', $field, 5, 4, $extra);
		$field = array_search("documentNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for database type
	function databaseForm($sessionVars)
	{
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->urlForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for manuscript type
	function manuscriptForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = '';
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
		}
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("typeOfManuscript", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("manuscriptNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for map type
	function mapForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("seriesTitle", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("typeOfMap", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for chart type
	function chartForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("nameOfFile", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("version", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$field = array_search("number", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("imageProgram", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("imageType", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("imageSize", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for statute type
	function statuteForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("code", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("codeNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("publicLawNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("session", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("section", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 20, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for patent type
	function patentForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("patentNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("patentVersionNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("patentType", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("intPatentTitle", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("intPatentNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("intPatentClassification", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("applicationNumber", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$field = array_search("publishedSource", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$field = array_search("legalStatus", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 30, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for personal type
	function personalForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->dateForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$field = array_search("typeOfCommunication", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for unpublished type
	function unpublishedForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "year");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("typeOfWork", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= $this->pagesForm($sessionVars);
		return $pString;
	}
// Display stage4 for music_album type
	function musicAlbumForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherFormB($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("medium", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for music_track type
	function musicTrackForm($sessionVars)
	{
		if($this->session->getVar("resource_collectionId"))
		{
// print existing Collection
			if($title = $this->session->getVar("resource_collection"))
				$pString = MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->codeToHtml($this->html->dbToFormTidy($title)));
			else
			{
				$title = $this->db->fetchOne($this->db->select(array('WKX_collection'), array('collectionTitle'), 
					' WHERE ' . $this->db->formatField('id') . '=' . $this->db->tidyInput($this->session->getVar("resource_collectionId"))));
				$pString = MISC::p(MISC::b($this->messages->text("resources", "collection") .  ":&nbsp;&nbsp;") . 
					$this->html->dbToFormTidy($title));
			}
			return $pString;
		}
		$type = $sessionVars['type'];
//		$pString = MISC::hr();
		$pString = '';
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= $this->collectionForm($sessionVars);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		$pString .= $this->publisherFormB($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("medium", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for music_score type
	function musicScoreForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("edition", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for miscellaneous type
	function miscellaneousForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = $this->publisherForm($sessionVars);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		$field = array_search("medium", $this->map->{$type}['resource']);
		$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Display stage4 for miscellaneous section type
	function miscellaneousSectionForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = '';
		if(!$this->session->getVar("resource_collectionId"))
		{
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= $this->collectionForm($sessionVars);
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= MISC::br();
			$pString .= $this->publisherForm($sessionVars);
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= MISC::br();
		}
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$extra = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= $this->textElement($sessionVars, 'resource_year', 'year1', 31, 30, $extra);
		if(!$this->session->getVar("resource_collectionId"))
		{
			$field = array_search("medium", $this->map->{$type}['resource']);
			$pString .= $this->textElement($sessionVars, 'resource', $field, 50, 255);
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// Form element for database table fields.
	function textElement($sessionVars, $table, $field, $size, $maxSize, $extra = FALSE)
	{
		$type = $sessionVars['type'];
		return TABLE::td($this->makeTextInput(array($field, $this->map->{$type}[$table][$field]),
			$sessionVars, $size, $maxSize) . $extra);
	}
/////////////////////////////////////////////////////////////////////////////////////// General methods
// create form for inputting names
	function nameForm($creators, $sessionVars, $num, $type)
	{
		$pString = '';
		for($index = 1; $index <= $num; $index++)
		{
			$pString .= TABLE::trStart();
			$subEntry = $type . "_" . $index . "_firstname";
			$entry = "resource_" . $subEntry;
			$id = $type . "_" . $index . "_id";
			$idLabel = 'resource_' . $id;
			$text = array_key_exists($subEntry, $sessionVars) ? $sessionVars[$subEntry] : FALSE;
			$pString .= TABLE::td(FORM::textInput(FALSE, $entry, $this->html->dbToFormTidy($text), 30, 255));
			$subEntry = $type . "_" . $index . "_initials";
			$entry = "resource_" . $subEntry;
			$text = array_key_exists($subEntry, $sessionVars) ? $sessionVars[$subEntry] : FALSE;
			$pString .= TABLE::td(FORM::textInput(FALSE, $entry, $this->html->dbToFormTidy($text), 6, 255));
			$subEntry = $type . "_" . $index . "_prefix";
			$entry = "resource_" . $subEntry;
			$text = array_key_exists($subEntry, $sessionVars) ? $sessionVars[$subEntry] : FALSE;
			$pString .= TABLE::td(FORM::textInput(FALSE, $entry, $this->html->dbToFormTidy($text), 11, 10));
			$subEntry = $type . "_" . $index . "_surname";
			$entry = "resource_" . $subEntry;
			$text = array_key_exists($subEntry, $sessionVars) ? $sessionVars[$subEntry] : FALSE;
			$pString .= TABLE::td(FORM::textInput(FALSE, 
				$entry, $this->html->dbToFormTidy($text), 30, 255) . " " . MISC::span('*', 'required'));
			if($creators)
			{
				if(array_key_exists($id, $sessionVars))
					$pString .= TABLE::td(FORM::selectedBoxValue(FALSE, $idLabel, 
					$creators, $sessionVars[$id], "0"));
				else
					$pString .= TABLE::td(FORM::selectFBoxValue(FALSE, $idLabel, $creators, "0"));
			}
			$pString .= TABLE::trEnd();
		}
		return $pString;
	}
// form input for collection information where 'collection' is the medium that a resource article is in
// e.g. journal for journal_article, CD for music track, newspaper for newspaper article.
	function collectionForm($sessionVars)
	{
		$type = $sessionVars['type'];
		if(($this->vars['action'] == 'resourceNew') || (array_key_exists('resource_collection_id', $this->vars) && 
		!$this->vars['resource_collection_id']) || (array_key_exists('resource_collectionId', $this->vars) && 
		!$this->vars['resource_collectionId']))
		{
			include_once("core/collection/COLLECTION.php");
			$collection = new COLLECTION($this->db);
			if($sessionVars['type'] == 'miscellaneous_section')
				$collections = $collection->grabAll();
			else
			{
				include_once("core/collection/COLLECTIONMAP.php");
				$map = new COLLECTIONMAP();
				$collections = $collection->grabAll($map->collectionTypes[$type]);
			}
		}
		else
			$collections = FALSE;
//		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
//		$pString .= TABLE::trStart();
		$pString = '';
		$hint = $collections ? $this->messages->text("hint", "publisherName") : FALSE;
//		$hint = FALSE;
		if($type == 'newspaper_article')
			$pString .= MISC::b($this->messages->text("resources", "newspaper")) . 
			MISC::br() . $hint;
		else if($type == 'magazine_article')
			$pString .= MISC::b($this->messages->text("resources", "magazine")) . 
			MISC::br() . $hint;
		else if($type == 'web_encyclopedia_article')
			$pString .= MISC::b($this->messages->text("resources", "encyclopedia")) . 
			MISC::br() . $hint;
		else if($type == 'manuscript')
			$pString .= MISC::b($this->messages->text("resources", "manuscript")) . 
			MISC::br() . $hint;
		else if(($type == 'proceedings_article') || ($type == 'proceedings') || ($type == 'conference_paper'))
			$pString .= MISC::b($this->messages->text("resources", "conference")) . 
			MISC::br() . $hint;
		else if(($type == 'journal_article') || ($type == 'web_article') || 
			($type == 'web_encyclopedia_article'))
			$pString .= MISC::b($this->messages->text("resources", "journal")) . 
			MISC::br() . $hint;
		else if(($type == 'book_article') || ($type == 'book_chapter'))
			$pString .= MISC::b($this->messages->text("resources", "bookTitle")) . 
			MISC::br() . $hint;
		else if($type == 'music_track')
			$pString .= MISC::b($this->messages->text("resources", "album")) . 
			MISC::br() . $hint;
		else if($type == 'miscellaneous_section')
			$pString .= MISC::b($this->messages->text("resources", "collection")) . 
			MISC::br() . $hint;
		if(($type == 'thesis') || ($type == 'web_article') || 
			($type == 'web_encyclopedia_article'))
			$required = FALSE;
		else
			$required = " " . MISC::span('*', 'required');
//		$pString .= TABLE::trEnd();
//		$pString .= TABLE::tableEnd();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= TABLE::td($this->makeTextInput(array('collection', 'collectionTitle'), 
			$sessionVars, 40, 255) . $required);
		$pString .= TABLE::td($this->makeTextInput(array('collectionShort', 'collectionShort'), 
			$sessionVars, 20, 255));

		if($collections)
		{
// add 0 => IGNORE to collections array
			$temp[0] = $this->messages->text("misc", "ignore");
			foreach($collections as $key => $value)
				$temp[$key] = $value;
			$collections = $temp;
			if(array_key_exists("collection_id", $sessionVars))
				$pString .= TABLE::td(MISC::br() . FORM::selectedBoxValue(FALSE, "resource_collection_id", 
				$collections, $sessionVars["collection_id"], "0"));
			else
				$pString .= TABLE::td(MISC::br() . FORM::selectFBoxValue(FALSE, "resource_collection_id", 
				$collections, "0"));
		}
		return $pString;
	}
// form input for publisher information.
	function publisherForm($sessionVars)
	{
		$type = $sessionVars['type'];
		include_once("core/publisher/PUBLISHER.php");
		$publisher = new publisher($this->db);
// Want all publishers for resource type miscellaneous
		if(($type == 'miscellaneous') || ($type == 'miscellaneous_section'))
			$publishers = $publisher->grabAll();
		else
			$publishers = $publisher->grabAll($type);
//		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
//		$pString .= TABLE::trStart();
		$hint = $publishers ? $this->messages->text("hint", "publisherName") : FALSE;
		if($type == 'report')
		{
			$title = $this->messages->text("resources", "institution");
			$name = "institution";
			$location = "publisherLocation";
		}
		else if($type == 'unpublished')
		{
			$title = $this->messages->text("resources", "institution");
			$name = "institution";
			$location = "publisherLocation";
		}
		else if($type == 'patent')
		{
			$title = $this->messages->text("resources", "assignee");
			$name = "assignee";
			$location = "publisherLocation";
		}
		else if($type == 'legal_ruling')
		{
			$title = $this->messages->text("resources", "publisher");
			$name = "publisherName";
			$location = "publisherLocation";
		}
		else if($type == 'hearing')
		{
			$title = $this->messages->text("resources", "hearing");
			$name = "hearing";
			$location = "publisherLocation";
		}
		else if($sessionVars['type'] == 'bill')
		{
			$title = $this->messages->text("resources", "legislativeBody");
			$name = "legislativeBody";
			$location = "publisherLocation";
		}
		else if($type == 'thesis')
		{
			$title = $this->messages->text("resources", "institution");
			$name = "institution";
			$location = "publisherLocation";
		}
		else if($type == 'broadcast')
		{
			$title = $this->messages->text("resources", "channel");
			$name = "channel";
			$location = "publisherLocation";
		}
		else
		{
			$title = $this->messages->text("resources", "publisher");
			$name = "publisherName";
			$location = "publisherLocation";
		}
		$pString = '';
		if(($type != 'proceedings_article') && ($type != 'proceedings') && ($type != 'conference_paper'))
		{
			$pString .= MISC::b($title) . MISC::br() . $hint;
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td($this->makeTextInput(array('publisherName', $name), $sessionVars, 40, 255));
			if($type == 'thesis')
			{
				$field = array_search("department", $this->map->{$type}['resource']);
				$pString .= $this->textElement($sessionVars, 'resource', $field, 40, 255);
			}
			$pString .= TABLE::td($this->makeTextInput(array('publisherLocation', $location), 
				$sessionVars, 30, 255));
			if($publishers)
			{
// add 0 => IGNORE to publishers array
				$temp[0] = $this->messages->text("misc", "ignore");
				foreach($publishers as $key => $value)
					$temp[$key] = $value;
				$publishers = $temp;
				$this->publishers = $publishers; // used in translationForm() below.
				if(array_key_exists("publisher_id", $sessionVars))
					$pString .= TABLE::td(MISC::br() . FORM::selectedBoxValue(FALSE, "resource_publisher_id", 
					$publishers, $sessionVars["publisher_id"], "0"));
				else
					$pString .= TABLE::td(MISC::br() . FORM::selectFBoxValue(FALSE, "resource_publisher_id", 
					$publishers, "0"));
//				$pString .= MISC::br() . "&nbsp;" . MISC::br();
			}
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
// Proceedings article and proceedings can also have a publisher in addition to conference organiser etc.
// This is a hack until I have time to code it better.
		if(($type == 'proceedings_article') || ($type == 'proceedings'))
		{
// Conference organizer -- goes in WKX_resource_misc.publisher
			$name = "conferenceOrganiser";
			$location = "conferenceLocation";
//			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
//			$pString .= TABLE::trStart();
			if($type == 'proceedings')
			{
				$title = $this->messages->text("resources", "conference");
				$pString .= MISC::b($title) . MISC::br() . $hint;
			}
//			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td($this->makeTextInput(array('publisherName', $name), 
				$sessionVars, 40, 255));
			$pString .= TABLE::td($this->makeTextInput(array('publisherLocation', $location), 
				$sessionVars, 30, 255));
			if($publishers)
			{
// add 0 => IGNORE to publishers array
				$temp[0] = $this->messages->text("misc", "ignore");
				foreach($publishers as $key => $value)
					$temp[$key] = $value;
				$publishers = $temp;
				if(array_key_exists("publisher_id", $sessionVars))
					$pString .= TABLE::td(MISC::br() . FORM::selectedBoxValue(FALSE, "resource_publisher_id", 
					$publishers, $sessionVars["publisher_id"], "0"));
				else
					$pString .= TABLE::td(MISC::br() . FORM::selectFBoxValue(FALSE, "resource_publisher_id", 
					$publishers, "0"));
			}
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= MISC::br();
// Proceedings publisher -- goes in miscField1
			$title = $this->messages->text("resources", "publisher");
			$name = "publisherName";
			$location = "publisherLocation";
//			$pString .= TABLE::trEnd();
//			$pString .= TABLE::tableEnd();
//			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
//			$pString .= TABLE::trStart();
			$pString .= MISC::b($title) . MISC::br() . $hint;
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td($this->makeTextInput(array('confPublisherName', $name), 
				$sessionVars, 40, 255));
			$pString .= TABLE::td($this->makeTextInput(array('confPublisherLocation', $location), 
				$sessionVars, 30, 255));
			if($publishers)
			{
// add 0 => IGNORE to publishers array
				$temp[0] = $this->messages->text("misc", "ignore");
				foreach($publishers as $key => $value)
					$temp[$key] = $value;
				$publishers = $temp;
				if(array_key_exists("confPublisher_id", $sessionVars))
					$pString .= TABLE::td(MISC::br() . FORM::selectedBoxValue(FALSE, "resource_confPublisher_id", 
					$publishers, $sessionVars["publisher_id"], "0"));
				else
					$pString .= TABLE::td(MISC::br() . FORM::selectFBoxValue(FALSE, "resource_confPublisher_id", 
					$publishers, "0"));
			}
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
		if(($type == 'conference_paper'))
		{
// Conference organizer -- goes in WKX_resource_misc.publisher
//			$title = $this->messages->text("resources", "conference");
			$name = "conferenceOrganiser";
			$location = "conferenceLocation";
//			$pString .= TABLE::trEnd();
//			$pString .= TABLE::tableEnd();
//			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
//			$pString .= TABLE::trStart();
//			$pString .= MISC::b($title) . MISC::br() . $hint;
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td($this->makeTextInput(array('publisherName', $name), 
				$sessionVars, 40, 255));
			$pString .= TABLE::td($this->makeTextInput(array('publisherLocation', $location), 
				$sessionVars, 30, 255));
			if($publishers)
			{
// add 0 => IGNORE to publishers array
				$temp[0] = $this->messages->text("misc", "ignore");
				foreach($publishers as $key => $value)
					$temp[$key] = $value;
				$publishers = $temp;
				if(array_key_exists("publisher_id", $sessionVars))
					$pString .= TABLE::td(MISC::br() . FORM::selectedBoxValue(FALSE, "resource_publisher_id", 
					$publishers, $sessionVars["publisher_id"], "0"));
				else
					$pString .= TABLE::td(MISC::br() . FORM::selectFBoxValue(FALSE, "resource_publisher_id", 
					$publishers, "0"));
			}
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
		}
		return $pString;
	}
// Form input for the original publisher details on which a translation is based
// form input for publisher information.
	function translationForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$hint = isset($this->publishers) ? $this->messages->text("hint", "publisherName") : FALSE;
		$title = $this->messages->text("resources", "translatedFrom");
		$pString = MISC::b($title) . MISC::br() . $hint;
//		$pString .= TABLE::trEnd();
//		$pString .= TABLE::tableEnd();
//		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br() . "&nbsp;" . MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$name = "publisher";
		$location = "publisherLocation";
		$pString .= TABLE::td($this->makeTextInput(array('transPublisherName', $name), $sessionVars, 40, 255));
		$pString .= TABLE::td($this->makeTextInput(array('transPublisherLocation', $location), 
			$sessionVars, 30, 255));
		if(isset($this->publishers))
		{
			if(array_key_exists("publisher_id", $sessionVars))
				$pString .= TABLE::td(MISC::br() . FORM::selectedBoxValue(FALSE, 
					"resource_transPublisher_id", $this->publishers, $sessionVars["publisher_id"], "0"));
			else
				$pString .= TABLE::td(MISC::br() . FORM::selectFBoxValue(FALSE,
					"resource_transPublisher_id", $this->publishers, "0"));
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		if(array_key_exists("transTitle", $sessionVars) && $sessionVars['transTitle'] == '(no title)')
			unset($sessionVars['transTitle']);
		$title = array_key_exists("transTitle", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars['transTitle']) : FALSE;
		$title = array_key_exists("transNoSort", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars['transNoSort']) . " $title" : FALSE . $title;
		$subtitle = array_key_exists("transSubtitle", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars['transSubtitle']) : FALSE;
		$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "title"), 
			"resource_transTitle", $title, 50) . MISC::br() . $this->messages->text("hint", "capitals"));
		$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "subtitle"), "resource_transSubtitle", 
			$subtitle, 50));
			
		$hint = MISC::br() . $this->messages->text("hint", "publicationYear");
		$pString .= TABLE::td($this->makeTextInput(array('year4', "publicationYear"), 
			$sessionVars, 31, 30) . $hint);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// form input for publisher information where there is no location information (e.g. film distributors etc.).
	function publisherFormB($sessionVars)
	{
		$type = $sessionVars['type'];
		include_once("core/publisher/PUBLISHER.php");
		$publisher = new publisher($this->db);
		$publishers = $publisher->grabAll($sessionVars['type']);
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$hint = $publishers ? $this->messages->text("hint", "publisherName") : FALSE;
		if($type == 'institution')
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "institution")) . 
			MISC::br() . $hint);
		else if($type == 'film')
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "distributor")) . 
			MISC::br() . $hint);
		else if($type == 'music_album')
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "recordLabel")) . 
			MISC::br() . $hint);
		else if($type == 'music_track')
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "recordLabel")) . 
			MISC::br() . $hint);
		else if($type == 'case')
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "court")) . 
			MISC::br() . $hint);
		else
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "publisher")) . 
			MISC::br() . $hint);
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		if($type == 'film')
			$label = 'distributor';
		else if($type == 'case')
			$label = 'court';
		else if($type == 'thesis')
			$label = 'institution';
		else
			$label = 'publisherName';
		$pString .= TABLE::td($this->makeTextInput(array("publisherName", $label), 
			$sessionVars, 50, 255));
		if($publishers)
		{
// add 0 => IGNORE to publishers array
			$temp[0] = $this->messages->text("misc", "ignore");
			foreach($publishers as $key => $value)
				$temp[$key] = $value;
			$publishers = $temp;
			if(array_key_exists("publisher_id", $sessionVars))
				$pString .= TABLE::td(MISC::br() . FORM::selectedBoxValue(FALSE, "resource_publisher_id", 
				$publishers, $sessionVars["publisher_id"], "0"));
			else
				$pString .= TABLE::td(MISC::br() . FORM::selectFBoxValue(FALSE, "resource_publisher_id", 
				$publishers, "0"));
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// form input for films/TV
	function filmTVForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		if($type == 'film')
		{
			$field = array_search("publicationYear", $this->map->{$type}['resource_year']);
			$pString .= TABLE::td($this->makeTextInput(array($field, 
				$this->map->{$type}['resource_year'][$field]), 
				$sessionVars, 31, 30) . MISC::br() . 
				$this->messages->text("hint", "publicationYear"));
			$field = $this->map->{$type}['resource']['field1'];
			$pString .= TABLE::td($this->makeTextInput(array('field1', $field), 
				$sessionVars, 30, 255));
		}
		$pString .= TABLE::td(MISC::b($this->messages->text("resources", "runningTime") . ":&nbsp;"), 
			FALSE, 'right', 'middle');
		$field = $this->map->{$type}['resource_misc']['miscField4'];
		$pString .= TABLE::td($this->makeTextInput(array('miscField4', $field), 
			$sessionVars, 5, 4));
		$field = $this->map->{$type}['resource_misc']['miscField1'];
		$pString .= TABLE::td($this->makeTextInput(array('miscField1', $field), 
			$sessionVars, 3, 2));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		return $pString;
	}
// form input for groups and keywords.
	function groupKeywordForm($sessionVars, $new)
	{
		include_once("core/group/GROUP.php");
		$group = new GROUP($this->db);
		$groups = $group->grabAll();
		if(sizeof($groups) > 1)
		{
// Put 1 => 'General' group at top of list
			unset($groups[1]);
			$temp[1] = 'General';
			foreach($groups as $key => $value)
				$temp[$key] = $value;
			$groups = $temp;
		}
		else
			$groups = FALSE;
		include_once("core/keyword/KEYWORD.php");
		$keyword = new KEYWORD($this->db);
		$keywords = $keyword->grabAll();
// add 0 => IGNORE to keywords array
		$temp = array();
		if($keywords)
		{
			$temp[0] = $this->messages->text("misc", "ignore");
			foreach($keywords as $key => $value)
				$temp[$key] = $value;
			$keywords = $temp;
		}
		$pString = '';
		if($groups)
		{
			$title = MISC::b($this->messages->text("resources", "categories")) . MISC::br() . 
			$this->messages->text("hint", "categories");
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			if(array_key_exists("group_ids", $sessionVars))
			{
				$selectedArray = explode(",", $sessionVars['group_ids']);
				$td = FORM::selectedBoxValueMultiple($title, "resource_group_ids", 
				$groups, $selectedArray, "6");
			}
			else
				$td = FORM::selectFBoxValueMultiple($title, "resource_group_ids", $groups, "6");
			$pString .= TABLE::td($td . MISC::br() . $this->messages->text("hint", "multiples"));
//			$pString .= TABLE::trEnd();
//			$pString .= TABLE::tableEnd();
			$pString .= MISC::br();
		}
//		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
//		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
//		$pString .= TABLE::trStart();
		$title = MISC::b($this->messages->text("resources", "keywords"));
		if($keywords)
		{
			if(array_key_exists("keyword_ids", $sessionVars))
			{
				$selectedArray = explode(",", $sessionVars['keyword_ids']);
				$td = FORM::selectedBoxValueMultiple($title, "resource_keyword_ids", 
					$keywords, $selectedArray, "6");
			}
			else
				$td = FORM::selectFBoxValueMultiple($title, "resource_keyword_ids", $keywords, "6");
			$pString .= TABLE::td($td . MISC::br() . $this->messages->text("hint", "multiples"));
			$title = '';
		}
		$title .= MISC::br() . $this->messages->text("hint", "keywords");
		$text = array_key_exists("keywords", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars["keywords"]) : FALSE;
		$pString .= TABLE::td($title . MISC::br() . FORM::textInput(FALSE, 
			"resource_keywords", $text, 40, 255) . MISC::br() . 
			$this->messages->text("hint", "keywordList"));
		$pString .= $this->addBibliography($sessionVars, $new);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br();
		return $pString;
	}
// Form input for adding a new item to user bibliographies
	function addBibliography($sessionVars, $new)
	{
		if(!$this->session->issetVar('mywikindx_bibliographies'))
			return FALSE;
		$bibs[0] = $this->messages->text("misc", "ignore");
// Get this user's bibliographies
		if($this->session->getVar('mywikindx_bibliographies'))
		{
			$bibsRaw = unserialize($this->session->getVar("mywikindx_bibliographies"));
			foreach($bibsRaw as $key => $value)
				$bibsU[$key] = $this->html->dbToFormTidy($value);
		}
// Get this user's user group bibliographies
		if($this->session->getVar('mywikindx_groupbibliographies'))
		{
			$bibsRaw = unserialize($this->session->getVar("mywikindx_groupbibliographies"));
			foreach($bibsRaw as $key => $value)
				$bibsUG[$key] = $this->html->dbToFormTidy($value);
		}
		if(!empty($bibsU))
		{
			foreach($bibsU as $key => $value)
				$bibs[$key] = $value;
		}
		if(!empty($bibsUG))
		{
			foreach($bibsUG as $key => $value)
				$bibs[$key] = $value;
		}
		if(!empty($otherBibs))
		{
			foreach($otherBibs as $key => $value)
				$bibs[$key] = $value;
		}
//		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
//		$pString .= TABLE::trStart();
		if($new && $this->session->issetVar('mywikindx_bibliography_use'))
		{
			$useBib = $this->session->getVar('mywikindx_bibliography_use');
			if(array_key_exists($useBib, $bibs))
			{
				$selectedArray[] = $useBib;
				$td = FORM::selectedBoxValueMultiple(
				$this->messages->text('resources', "addNewResourceToBib"), 
				"resource_bib_ids", $bibs, $selectedArray, "6");
			}
			else
				$td = FORM::selectFBoxValueMultiple(
				$this->messages->text('resources', "addNewResourceToBib"), "resource_bib_ids", $bibs, "6");
		}
		else
		{
			if(!$new)
			{
				$userId = $this->session->getVar('setup_userId');
				$recordSet = $this->db->select(array("WKX_user_bibliography"), 'id', 
					" WHERE " . $this->db->formatfield('userId') . "=" . $this->db->tidyInput($userId) . 
// NB MySQL bug: http://bugs.mysql.com/bug.php?id=2047 -- append comma temporarily
					" AND FIND_IN_SET(" . $this->db->tidyInput($sessionVars['resourceId']) . ", CONCAT(" . 
					$this->db->formatField('bibliography') . ", ','))");
				while($row = $this->db->loopRecordSet($recordSet))
					$selectedArray[] = $row['id'];
				if(isset($selectedArray))
					$td = FORM::selectedBoxValueMultiple(
					$this->messages->text('resources', "addNewResourceToBib"), 
					"resource_bib_ids", $bibs, $selectedArray, "6");
				else
					$td = FORM::selectFBoxValueMultiple(
					$this->messages->text('resources', "addNewResourceToBib"), 
					"resource_bib_ids", $bibs, "6");
			}
			else
				$td = FORM::selectFBoxValueMultiple($this->messages->text('resources', "addNewResourceToBib"), 
				"resource_bib_ids", $bibs, "6");
		}
		$td .= MISC::br() . $this->messages->text("hint", "multiples");
		if(!$new)
			$td .= MISC::p($this->messages->text("misc", "removeFromBibliographies") . ":&nbsp;&nbsp;" . 
			FORM::checkbox(FALSE, "resource_removeFromBibliographies", FALSE, "left", "bottom"));
		$pString = TABLE::td($td);
//		$pString .= TABLE::trEnd();
//		$pString .= TABLE::tableEnd();
//		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		return $pString;
	}
// form input for URLs at stage 4 (web_site, web_article, web_encyclopedia, web_encyclopedia_article and online databases)
	function urlForm($sessionVars)
	{
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$text = array_key_exists("url", $sessionVars) ? $this->html->dbToFormTidy($sessionVars["url"]) : 
			$this->messages->text("resources", "urlForm");
		$td = MISC::b($this->messages->text("resources", "url")) . MISC::br();
		$required = " " . MISC::span('*', 'required');
		$url = array_key_exists("url", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars['url']) : "http://";
		$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "url"), 
			"resource_url", $url, 70, 255) . " " . $required  . 
			MISC::br() . $this->messages->text("hint", "url"));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		return $pString;
	}
// form input for URLs and ISBN/ISSN at Stage5
	function urlIsbnForm($sessionVars, $webArticle = FALSE)
	{
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$text = array_key_exists("url", $sessionVars) ? $this->html->dbToFormTidy($sessionVars["url"]) : 
			$this->messages->text("resources", "urlForm");
		$td = MISC::b($this->messages->text("resources", "url")) . MISC::br();
		if(!$webArticle)
		{
			$td .= $this->messages->text("hint", "urlNote") . MISC::br();
			$required = FALSE;
			$url = array_key_exists("url", $sessionVars) ? 
				$this->html->dbToFormTidy($sessionVars['url']) : "http://";
			$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", "url"), 
				"resource_url", $url, 70, 255) . " " . $required  . 
				MISC::br() . $this->messages->text("hint", "url"));
		}
		if(array_key_exists('doi', $sessionVars))
			$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", 'doi'), "resource_doi", 
				$this->html->dbToFormTidy($sessionVars['doi']), 30, 255));
		else
			$pString .= TABLE::td(FORM::textInput($this->messages->text("resources", 'doi'), "resource_doi", 
				FALSE, 30, 255));
		$pString .= TABLE::td($this->makeTextInput('isbn', $sessionVars, 30, 255));
		if(array_search("peerReviewed", $this->map->{$sessionVars['type']}['possible']) !== FALSE)
		{
			$peer = array_key_exists('peerReviewed', $sessionVars) && $sessionVars['peerReviewed'] == 'Y' ? 'CHECKED' : FALSE;
			$pString .= TABLE::td(FORM::checkbox($this->messages->text("resources", "peerReviewed"), 
				"resource_peerReviewed", $peer), "left", "bottom");
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		return $pString;
	}
// form input for date (day/month/year) - miscField2, miscField3 and yearx fields.
// If $endDate, this is end date so handles miscField5, miscField6 and year3
	function dateForm($sessionVars, $endDate = FALSE)
	{
		$type = $sessionVars['type'];
		if(!$endDate)
		{
			$dayField = "miscField2";
			$monthField = "miscField3";
			$yearField = "year1";
		}
		else
		{
			$dayField = "miscField5";
			$monthField = "miscField6";
			$yearField = "year3";
		}
// Load month arrays
		include_once("core/messages/CONSTANTS.php");
		$constant = new CONSTANTS();
		$pString = '';
		$days[] = $this->messages->text("misc", "ignore");
		$days = array_merge($days, range(1, 31));
		$months[] = $this->messages->text("misc", "ignore");
		$months = array_merge($months, $constant->constants->monthToLongName());
		$dayText = $monthText = 0;// 'IGNORE'
		if(array_key_exists($dayField, $sessionVars) && $sessionVars[$dayField])
			$dayText = $sessionVars[$dayField];
		if(array_key_exists($monthField, $sessionVars) && $sessionVars[$monthField])
			$monthText = $sessionVars[$monthField];
		if(!isset($sessionVars[$yearField]) || !$sessionVars[$yearField])
			$sessionVars[$yearField] = FALSE;
		$required = '';
		if(($sessionVars['type'] == 'web_site') || ($sessionVars['type'] == 'web_article') || 
			($sessionVars['type'] == 'database') || ($sessionVars['type'] == 'web_encyclopedia') ||
			($sessionVars['type'] == 'web_encyclopedia_article'))
		{
			$days = range(0, 31);
			unset($days[0]);
			$months = $constant->constants->monthToLongName();
			if(!$dayText || !$monthText)
			{
				$dayText = date("j");
				$monthText = date("n");
			}
			$yearField = "year2";
			if(!isset($sessionVars["year2"]) || !$sessionVars["year2"])
				$sessionVars["year2"] = date("Y");
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "dateAccessed")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = " " . MISC::span('*', 'required');
		}
		else if($sessionVars['type'] == 'broadcast')
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "broadcastDate")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		else if($sessionVars['type'] == 'legal_ruling')
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "codeEditionDate")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		else if($sessionVars['type'] == 'case')
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "dateDecided")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		else if($sessionVars['type'] == 'patent')
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "issueDate")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		else if($sessionVars['type'] == 'statute')
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "dateEnacted")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		else if($sessionVars['type'] == 'report')
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "reportDate")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		else if($sessionVars['type'] == 'hearing')
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b($this->messages->text("resources", "hearingDate")));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		else if(($sessionVars['type'] == 'proceedings') || ($sessionVars['type'] == 'proceedings_article')
			 || ($sessionVars['type'] == 'conference_paper'))
		{
			if(!$endDate)
				$yearField = "year2";
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			if($endDate)
				$pString .= TABLE::td(MISC::b($this->messages->text("resources", "conferenceDate") . 
					" (" . $this->messages->text("resources", "dateEnd") . ")"));
			else
				$pString .= TABLE::td(MISC::b($this->messages->text("resources", "conferenceDate") . 
					" (" . $this->messages->text("resources", "dateStart") . ")"));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		else if((($sessionVars['type'] == 'magazine_article') || 
			($sessionVars['type'] == 'journal_article')) && $endDate)
		{
			$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
			$pString .= TABLE::trStart();
			$pString .= TABLE::td(MISC::b(" (" . $this->messages->text("resources", "dateEnd") . ")"));
			$pString .= TABLE::trEnd();
			$pString .= TABLE::tableEnd();
			$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
			$required = '';
		}
		$pString .= TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		if($sessionVars['type'] != 'journal_article')
			$pString .= TABLE::td(FORM::selectedBoxValue($this->messages->text("resources", "day"),
			"resource_$dayField", $days, $dayText, "0") . $required);
		$pString .= TABLE::td(FORM::selectedBoxValue($this->messages->text("resources", "month"), 
			"resource_$monthField", $months, $monthText, "0", "12") . $required);
		$pString .= TABLE::td($this->makeTextInput(array($yearField, "year"), $sessionVars, 31, 30) . 
			$required . '&nbsp;' . $this->messages->text("hint", "year"));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		return $pString;
	}
// form input for resource Abstract
	function abstractForm($sessionVars)
	{
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$text = array_key_exists("abstract", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars["abstract"]) : FALSE;
		$pString .= TABLE::td(FORM::textareaInput(MISC::b($this->messages->text("resources", "abstract")), 
			"resource_abstract", $text, 60, 10));
		$pString .= $this->noteForm($sessionVars);
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		return $pString;
	}
// form input for resource Note
	function noteForm($sessionVars)
	{
//		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
//		$pString .= TABLE::trStart();
		$text = array_key_exists("note", $sessionVars) ? 
			$this->html->dbToFormTidy($sessionVars["note"]) : FALSE;
		$pString = TABLE::td(FORM::textareaInput(MISC::b($this->messages->text("resources", "note")), 
			"resource_note", $text, 60, 10));
//		$pString .= TABLE::trEnd();
//		$pString .= TABLE::tableEnd();
//		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		return $pString;
	}
// form input for file attachments
	function fileAttachForm($sessionVars, $new)
	{
		if(!$this->session->getVar("setup_fileAttach"))
			return FALSE;
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$text = array_key_exists("fileAttach", $sessionVars) ? $sessionVars["fileAttach"] : FALSE;
		$pString .= TABLE::td(FORM::fileUpload($this->messages->text("resources", "fileAttach"), 
			"resource_fileAttach", 20), FALSE, "left", "bottom");
		$pString .= TABLE::td($this->messages->text("resources", "fileName") . "&nbsp;" . FORM::textInput(FALSE, 
			"resource_fileName"), FALSE, "left", "bottom");
		if(!$new && array_key_exists('file', $sessionVars)) // editing
		{
			$pString .= TABLE::td($this->messages->text("resources", "fileRemove", $sessionVars['file']) . 
				":&nbsp;&nbsp;" . FORM::checkbox(FALSE, "resource_fileRemove"), FALSE, "left", "bottom");
		}
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::br() . "&nbsp;" . MISC::hr() . MISC::br();
		return $pString;
	}
// form input for custom fields
	function customFields($sessionVars, $new)
	{
		$recordset = $this->db->select(array("WKX_custom"), array('id', 'custom_label', 'custom_size'));
		if(!$this->db->numRows($recordset))
			return FALSE;
// existing data
		if(!$new)
		{
			$recordset2 = $this->db->select(array('WKX_resource_custom'), array('id', 'customId', 
				'custom_short', 'custom_long'), 
				" WHERE " . $this->db->formatfield('resourceId') ."=" . 
				$this->db->tidyInput($sessionVars['resourceId']));
			while($row = $this->db->loopRecordSet($recordset2))
			{
				if(trim($row['custom_short']))
					$customText[$row['customId']] = 
					$this->html->dbToFormTidy(trim($row['custom_short']));
				else if(trim($row['custom_long']))
					$customText[$row['customId']] = 
					$this->html->dbToFormTidy(trim($row['custom_long']));
			}
		}
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= TABLE::td(MISC::b($this->messages->text("custom", "customFields")));
		$pString .= TABLE::trEnd();
		while($row = $this->db->loopRecordSet($recordset))
		{
			if(isset($customText) && array_key_exists($row['id'], $customText))
				$text = $customText[$row['id']];
			else
				$text = FALSE;
			$formName = "resource_custom_" . $row['custom_size'] . "_" . $row['id'];
			$pString .= TABLE::trStart();
			if($row['custom_size'] == 'S') // small VARCHAR(255)
				$pString .= TABLE::td(MISC::br() . "&nbsp;" . 
					FORM::textInput($this->html->dbToHtmlTidy($row['custom_label']), 
					$formName, $text, 50, 255));
			else // large TEXT
				$pString .= TABLE::td(MISC::br() . "&nbsp;" . 
					FORM::textareaInput($this->html->dbToHtmlTidy($row['custom_label']), 
					$formName, $text, 80, 10));
			$pString .= TABLE::trEnd();
		}
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
		$pString .= MISC::hr();
		return $pString;
	}
// form input for pages
	function pagesForm($sessionVars)
	{
		$type = $sessionVars['type'];
		$pString = TABLE::tableStart(FALSE, 0, 0, 0, "left");
		$pString .= TABLE::trStart();
		$pString .= TABLE::td($this->messages->text("resources", "pages") . MISC::br() . 
			$this->messages->text("hint", "pages"));
		$pString .= TABLE::td($this->makeTextInput(array("pageStart", "pageStart"), $sessionVars, 10, 9));
		$pString .= TABLE::td($this->makeTextInput(array("pageEnd", "pageEnd"), $sessionVars, 10, 9));
		$pString .= TABLE::trEnd();
		$pString .= TABLE::tableEnd();
		$pString .= TABLE::tdEnd() . TABLE::trEnd() . TABLE::trStart() . TABLE::tdStart();
//		$pString .= MISC::br();
		return $pString;
	}
}
?>

